package com.example.gesture

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.example.gesture.ui.theme.JetpackComposeBasicTheme

/**
 * @author huangzehui
 * @date 12/5/2024 下午10:40 周日
 * @description
 *
 * 嵌套滚动
 * https://www.bilibili.com/video/BV1ob4y1a7ad?p=64&spm_id_from=pageDriver&vd_source=e07cc8cc94eb22bd76722071b03cd199
 */
class MainActivity02 : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            JetpackComposeBasicTheme {
                Demo1()
            }
        }
    }

    /**
     * 嵌套滚动
     *
     * https://www.bilibili.com/video/BV1ob4y1a7ad?p=64&spm_id_from=pageDriver&vd_source=e07cc8cc94eb22bd76722071b03cd199
     */
    @Composable
    fun Demo1() {
        // 渐变颜色
        val gradient = Brush.verticalGradient(
            0f to Color.Gray, 1000f to Color.White
        )

        Box(
            modifier = Modifier
                .background(Color.LightGray)
                .verticalScroll(rememberScrollState())
                .padding(32.dp)
                .fillMaxSize(),
            contentAlignment = Alignment.Center
        ) {
            Column {
                repeat(16) { index ->
                    Box(
                        modifier = Modifier
                            .height(128.dp)
                            .verticalScroll(rememberScrollState())
                    ) {
                        Text(
                            text = "Scroll here ${index}", modifier = Modifier
                                .border(12.dp, Color.DarkGray)
                                .background(brush = gradient)
                                .padding(24.dp)
                                .height(150.dp)
                        )
                    }
                }
            }
        }
    }

}